/**
 * File: FileIndexReader.java
 * Created by: mhaimel
 * Created on: 15 Jul 2009
 * CVS:  $Id: FileIndexReader.java,v 1.1 2009/08/05 15:16:11 mhaimel Exp $
 */
package uk.ac.ebi.curtain.util;

import java.io.Closeable;
import java.io.IOException;

import uk.ac.ebi.curtain.util.FileIndexUtil.FileIndexEvent;
import uk.ac.ebi.curtain.utils.file.FileInfo;

/**
 * @author mhaimel
 *
 */
public interface FileIndexReader extends Closeable {

	void setEventHandler(FileIndexEvent handler);
	void setEventHandler(FileIndexEvent handler, IndexFilter filter);
	
	void open() throws IOException;
	void close() throws IOException;
	
	void registerFileId(Integer fileId, FileInfo info);
	
	/**
	 * Read through all entries
	 * @throws IOException
	 */
	void readAll() throws IOException;
	
	/**
	 * 
	 * @param nLines N number of lines
	 * @return boolean File reached end
	 * @throws IOException
	 */
	boolean readBlock(Integer nLines) throws IOException;
	
	public static class IndexFilter{
		private boolean read = false;
		private boolean contig = false;
		private boolean info = false;
		public void allowRead(boolean read) {
			this.read = read;
		}
		public boolean isReadAllow() {
			return read;
		}
		public void allowContig(boolean contig) {
			this.contig = contig;
		}
		public boolean isContigAllow() {
			return contig;
		}
		public void allowFileInfo(boolean info) {
			this.info = info;
		}	
		public boolean isFileInfoAllow() {
			return info;
		}	
		public void allowAll(boolean allow){
			this.allowContig(allow);
			this.allowRead(allow);
			this.allowFileInfo(allow);
		}
	}
}
